package com.koubei.distribute.common;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class AtomicTest {

	private static final int maxPoolSize = 20;
	
	public void testAtomic(){
		ExecutorService fixedPool = Executors.newFixedThreadPool(maxPoolSize);
		AtomicIntegerClass atomicNum = new AtomicIntegerClass(1,6,1);
		for(int i = 0; i<1000; i++){
			fixedPool.execute(new TestHandler(atomicNum));
		}
		fixedPool.shutdown();
	}
	
	public static void main(String[] args){
		AtomicTest ato = new AtomicTest();
		ato.testAtomic();
	}
	
	class TestHandler implements Runnable {
		private final AtomicIntegerClass atomicNum;
		public TestHandler(AtomicIntegerClass atomic){
			atomicNum = atomic;
		}
		public void run() {
			for(int i = 0; i<10; i++)
				System.out.println("==="+atomicNum.nextNum());
		}
	}
}
